package com.primal.server;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * @author:whh
 * @date: 2024-01-18 21:21
 * <p></p>
 */
public class JettyServer {


    public static final String DEFAULT_CONTEXT_PATH = "/primal";

    public static final String DEFAULT_URL_MAPPING = "/*";
    public static void main(String[] args) throws Exception {


        Server server = new Server(9999);


        XmlWebApplicationContext ctx = new XmlWebApplicationContext();
        ctx.setConfigLocation("classpath:beans.xml");
        ctx.registerShutdownHook();

        ServletContextHandler servletContextHandler = new ServletContextHandler();
        servletContextHandler.setContextPath(DEFAULT_CONTEXT_PATH);
        ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(ctx));
        servletHolder.setAsyncSupported(true);
        servletContextHandler.addServlet(servletHolder, DEFAULT_URL_MAPPING);
        server.setHandler(servletContextHandler);
        server.start();
        server.join();
    }
}
